package com.lagou.lagouserviceuser.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lagou.lagouserviceuser.mapper.UserMapper;
import com.lagou.lagouserviceuser.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

/**
 * @Authther: mrwu
 * @date:2021/4/14-04
 * @Description:com.lagou.lagouserviceuser.service
 */
@Service
public class UserServiceImpl implements UserService{
    @Autowired
    private UserMapper userMapper;
    @Override
    public User getuserByEmail(String email) {
        return userMapper.getUserByEmail(email);
    }

    @Transactional(rollbackFor = Exception.class) //使用事务注解
    @Override
    public boolean registUser(User user) {
        int insert = userMapper.insert(user);
        return insert>0;
    }

    //单表查询无需事务
//    @Transactional
    @Override
    public User quryUser(User user) {
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.eq("email", user.getEmail());
        userQueryWrapper.eq("password", user.getPassword());
        return userMapper.selectOne(userQueryWrapper);
    }
}
